#include "control.h"

Control::Control(CL_DisplayWindow* window) {
	this->resourceManager = ResourceManager::getInstance();
	this->model = GameModel::getInstance();
	this->window = window;
}

Control::~Control(void) {
}

void Control::getInput() {
	CL_InputDevice keyboard = window->get_ic().get_keyboard();

	if (keyboard.get_keycode(CL_KEY_RIGHT)) {
		model->playerMoveRight();
	}
	if (keyboard.get_keycode(CL_KEY_LEFT)) {
		model->playerMoveLeft();
	}
	if (keyboard.get_keycode(CL_KEY_SPACE)) {
		model->playerJump();
	}
	if (keyboard.get_keycode(CL_KEY_ESCAPE)) {
		// beenden
		model->isGameRunning = false;
	}
	if (!keyboard.get_keycode(CL_KEY_LEFT) && !keyboard.get_keycode(
			CL_KEY_RIGHT) && !keyboard.get_keycode(CL_KEY_SPACE)
			&& !keyboard.get_keycode(CL_KEY_ESCAPE) && !model->fallDownActive
			&& !model->continueJump) {
		resourceManager->getPlayer()->setPlayerState(PlayerDirection::NONE);
	}
}

void Control::getInputForEnding() {
	CL_InputDevice keyboard = window->get_ic().get_keyboard();

	if (keyboard.get_keycode(CL_KEY_SPACE)) {
		model->isGameRunning = false;
	}
	if (keyboard.get_keycode(CL_KEY_ESCAPE)) {
		model->isGameRunning = false;
	}
}
